<template>
  <div class="login">
    <div class="login-container">
      <h2 class="login-title">用户登录</h2>
      <form @submit.prevent="handleLogin" class="login-form">
        <div class="form-group">
          <label for="username">用户名：</label>
          <input id="username" v-model="form.username" type="text" placeholder="请输入用户名" required />
        </div>

        <div class="form-group">
          <label for="password">密码：</label>
          <input id="password" v-model="form.password" type="password" placeholder="请输入密码" required />
        </div>

        <button type="submit" class="login-button">登录</button>
      </form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

interface LoginForm {
  username: string
  password: string
}

const router = useRouter()
const form = ref<LoginForm>({
  username: '',
  password: ''
})

const handleLogin = () => {
  if (form.value.username && form.value.password) {
    console.log('登录信息:', form.value)
    alert('登录成功！')
    router.push('/home') // 登录成功后跳转到首页
  } else {
    alert('请输入用户名和密码')
  }
}
</script>

<style lang="scss" scoped>
$primary-color: #007bff;
$hover-color: darken($primary-color, 10%);
$border-radius: 4px;

.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;

  &-container {
    background-color: #fff;
    padding: 20px;
    border-radius: $border-radius;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
  }

  &-title {
    text-align: center;
    margin-bottom: 15px;
    font-size: 20px;
  }

  &-form {
    .form-group {
      margin-bottom: 10px;
    }

    label {
      display: block;
      margin-bottom: 5px;
      font-weight: 500;
    }

    input {
      width: 100%;
      padding: 5px;
      border: 1px solid #ccc;
      border-radius: $border-radius;
    }
  }

  &-button {
    width: 100%;
    padding: 8px;
    background-color: $primary-color;
    color: white;
    border: none;
    border-radius: $border-radius;
    cursor: pointer;
    font-size: 14px;

    &:hover {
      background-color: $hover-color;
    }
  }
}
</style>